<template>
  <div id="app" @click="handleTime">
    <router-view/>
  </div>
</template>

<script>
export default{
  name: 'App',
  data() {
    return {
      timmer: null,
      lastTime: null
    }
  },
  created() {
    this.lastTime = new Date()

    window.addEventListener('resize', () => {
      this.handleTime()
    })

    window.addEventListener('scroll', () => {
      if (this.timmer) {
        clearTimeout(this.timmer)
      }

      this.timmer = setTimeout(() => {
        this.handleTime()
      }, 3000)
    }, true)
  },
  methods: {
    handleTime() {
      const curTime = new Date()
      if (curTime - this.lastTime > 1000 * 60 * 30) {
        if (/Android|webOS| iPhone | iPad | iPod |BlackBerry|opera mini|opera mobile|appleWebkit.*mobile|mobile/i.test(navigator.userAgent)) {
          this.$router.push({ path: '/mobile/login/userlogin' })
        } else {
          this.$router.push({ path: '/login/index' })
        }
        /*this.$notify.error({
          title: '失败',
          message: '登录超时，请重新登录'
        })*/
        setTimeout(() => {
          this.$store.dispatch('FedLogOut').then(() => {
            if (/Android|webOS| iPhone | iPad | iPod |BlackBerry|opera mini|opera mobile|appleWebkit.*mobile|mobile/i.test(navigator.userAgent)) {
              this.$router.push({ path: '/mobile/login/userlogin' })
            } else {
              this.$router.push({ path: '/login/index' })
            }
            location.reload()
          })
        }, 20)
      } else {
        this.lastTime = curTime
      }
    }
  }

}
</script>
